﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data.SqlClient;

namespace DataAccess_Layer
{
    public static class RetailCenter_DAC
    {
        public static List<RetailCenterDTO> getAll()
        {
            List<RetailCenterDTO> centers = null;

            DataAccessHelper helper = null;
            SqlDataReader rdr = null;
            try
            {
                helper = new DataAccessHelper();
                rdr = helper.excuteSP("SP_Get_All_Retail_Center");

                if (rdr.HasRows)
                {
                    centers = new List<RetailCenterDTO>();
                    while (rdr.Read())
                    {
                        RetailCenterDTO center = createRetailCenter(ref rdr);
                        centers.Add(center);
                    }
                }
            }
            finally
            {
                helper.close();
                rdr.Close();
            }

            return centers;
        }
        private static RetailCenterDTO createRetailCenter(ref SqlDataReader rdr)
        {
            RetailCenterDTO center = new RetailCenterDTO();
            center.ID = (long)rdr["ID"];
            center.Name = rdr["Name"].ToString();
            center.District = rdr["District"].ToString();
            center.Ward = rdr["Ward"].ToString();
            center.Address = rdr["Address"].ToString();
            center.Phone = rdr["Phone"].ToString();

            return center;
        }
    } 
}
